home *** CD-ROM | disk | FTP | other *** search
- Path: news.cuny.edu!not-for-mail
- From: dzielins@its.brooklyn.cuny.edu (Daniel Zielinski)
- Newsgroups: comp.lang.c
- Subject: help with queue
- Date: 19 Apr 1996 00:11:45 -0400
- Organization: Brooklyn College
- Message-ID: <4l73q1$148@itsop2.its.brooklyn.cuny.edu>
- NNTP-Posting-Host: itsop2.its.brooklyn.cuny.edu
-
- Could anybody help me with QUEUE structure? It's node based.
- It seems that assert function fails (It's in the removeQueue function)
- Whenever I try to remove something from a QUEUE I get:
- line 31 in QUEUE.c assert failed.
- Any clues on what I'm doing wrong would be apriciated.
-
- this is QUEUE.c
-
-
-
- #include "QUEUE.h"
- #include <assert.h>
- #include <stdio.h>
-
- void
- insertQueue(Queue *qp,DataType d) {
- Node *np=newNode();
-
- setDataNode(np,d);
- qp->rear=np;
- if (qp->front==NULL)
- qp->front=np;
- else
- qp->rear->next=np;
- }
-
- int
- emptyQueue(Queue q) {
- assert((q.front==NULL && q.rear==NULL) || (q.front!=NULL &&
- q.rear!=NULL));
- return q.front==NULL;
- }
-
- DataType
- removeQueue(Queue *qp) {
- Node *np;
- DataType d;
-
- assert(!emptyQueue(*qp)); <-------- THIS IS THE LINE
- np=qp->front;
- d=np->data;
- qp->front=np->next;
- if (qp->front==NULL)
- qp->rear=NULL;
- deleteNode(np);
- return d;
- }
-
- void
- initQueue(Queue *qp) {
- qp->front=qp->rear=NULL;
- }
-
-
- thanks
-
-